import numpy as np
def f(x):
    return x[0] ** 2 + 25 * x[1] ** 2
def grad_f(x):
    return np.array([2 * x[0], 50 * x[1]])
def hessian_f(x):
    return np.array([[2, 0], [0, 50]])

def newton_method(x0, epsilon, max_iter=1000):
    x = np.array(x0)
    for i in range(max_iter):
        grad = grad_f(x)
        hess = hessian_f(x)
        if np.linalg.norm(grad) < epsilon:
            break
        x =x - np.linalg.inv(hess) @ grad
    return x


# 初始值
x0 = np.array([2, 2])
# 终止误差
epsilon = 0.001

# 执行Newton法
x_min = newton_method(x0, epsilon)
print("Minimum found at:", x_min)
print("Function value at minimum:", f(x_min))